﻿@using Admin.Models.Report
@{
    ViewBag.Title = "预约挂号统计";
}

@( Html.Kendo().Grid<ApptViewModel>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(p => p.CardNo).Filterable(f => f.Operators(o => o.ForString(d => d.Clear().IsEqualTo("等于").Contains("包含")))).Width(125);
                columns.Bound(p => p.OrderNo).Filterable(f => f.Operators(o => o.ForString(d => d.Clear().IsEqualTo("等于").Contains("包含")))).Width(165);
                columns.Bound(p => p.WxTranscationId).Filterable(f => f.Operators(o => o.ForString(d => d.Clear().IsEqualTo("等于").Contains("包含")))).Width(230);
                columns.Bound(p => p.RegDate).Width(140).Filterable(false);
                columns.Bound(p => p.StartTime).Width(100).Filterable(false);
                columns.Bound(p => p.EndTime).Width(100).Filterable(false);
                columns.Bound(p => p.PayState).Width(140).Filterable(ftb => ftb.Messages(x => x.SelectedItemsFormat("{0}项已选择")).Multi(true).BindTo(new[]{
                        new { Text = "0"},
                        new { Text = "1"},
                        new { Text = "2" },
                        new { Text = "3" },
                        new { Text = "4" }
                }).ItemTemplate("itemTemplate"))
                .ClientTemplate("<strong>#: convertPayState(PayState) # </strong>");
                columns.Bound(p => p.Fee).Width(100).Filterable(false).Format("{0:c}");
                columns.Bound(p => p.TreatFee).Width(100).Filterable(false).Format("{0:c}");
                columns.Bound(p => p.SumFee).Width(100).Filterable(false).Format("{0:c2}");
                columns.Bound(p => p.CreatedTime).Filterable(f => f.Operators(o => o.ForDate(d => d.Clear().IsEqualTo("等于").IsGreaterThan("大于").IsGreaterThanOrEqualTo("大于等于").IsLessThan("小于").IsLessThanOrEqualTo("小于等于")))).Filterable(f => f.Operators(o => o.ForDate(d => d.Clear().IsEqualTo("等于").IsGreaterThan("大于").IsGreaterThanOrEqualTo("大于等于").IsLessThan("小于").IsLessThanOrEqualTo("小于等于")))).Width(140).Format("{0:yyyy-MM-dd HH:mm:ss}");
                columns.Bound(p => p.PayTime).Filterable(f => f.Operators(o => o.ForDate(d => d.Clear().IsEqualTo("等于").IsGreaterThan("大于").IsGreaterThanOrEqualTo("大于等于").IsLessThan("小于").IsLessThanOrEqualTo("小于等于")))).Width(140).Format("{0:yyyy-MM-dd HH:mm:ss}");
            })
             .ToolBar(tools => tools.Excel().Text("导出"))
            .Excel(excel => excel
            .FileName("预约挂号统计.xlsx")
            .Filterable(true)
            .ProxyURL(Url.Action("Excel_Export_Save", "Grid"))
            )
            .HtmlAttributes(new { style = "height: 550px;" })
            .Filterable()
            .Pageable()
            .Navigatable()
            .Sortable()
            .Scrollable(scr => scr.Height(550))
            .DataSource(dataSource => dataSource
                .Ajax()
                //.Aggregates(aggregates =>
                //{
                //    aggregates.Add(p => p.SumFee).Sum();
                //    aggregates.Add(p => p.OrderNo).Count();
                //})
                .PageSize(20)
                .Events(events => events.Error("error_handler"))
                .Model(model => model.Id(p => p.Id))
                .Read("Appts_Read", "Grid")

            )
      )
<script type="text/javascript">
    function convertPayState(payState) {
        var _payState;
        switch(payState) {
            case "0":
                _payState = "未付款";
                break;
            case "1":
                _payState = "已付款";
                break;
            case "2":
                _payState = "退款中";
                break;
            case "3":
                _payState = "已退款";
                break;
            case "4":
                _payState = "退款失败";
                break;
        }
        return _payState;
    }
    function itemTemplate(e) {
        //handle the other checkboxes
        if (e.field == "all") {
            //handle the check-all checkbox template
            return "<div><label><strong><input type='checkbox' />全选</strong></label></div>";
        } else {
            return "<span><label><input type='checkbox' style='opacity: initial;position: unset;left:  unset;z-index: unset;width: auto;height: auto;' name='" + e.field + "' value='#= Text #'/><span>#= convertPayState(Text) #</span></label></span>";
        }
    }

    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }

    $(".sidebar-menu li").removeClass("active");
    $("#apptReport").addClass("active");
</script>